package org.dtrd.modules.shop.entity.bean;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.common.util.DateUtils;
import org.dtrd.common.util.StringUtil;
import org.dtrd.config.pay.OrderUtil;
import org.dtrd.modules.shop.entity.po.DtrdEntRdPayRefundFlow;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *
 * </p>
 *
 * @author xiao
 * @since 2022-06-23
 */
@Getter
@Setter
@ApiModel(value = "详情")
public class PayRefundFlowDetail {

    private Integer dataId;

    @NotNull
    @Min(value = 1)
    @ApiModelProperty(value = "医生ID", required = true)
    private Integer flowDoctorId;

    @NotNull
    @Range(min = 1, max = 2)
    @ApiModelProperty(value = "收退款类型：1-收钱，2-退款", required = true)
    private Integer flowType;

    @NotNull
    @Min(value = 1)
    @ApiModelProperty(value = "患者ID", required = true)
    private Integer flowPatientId;

    @NotBlank
    @ApiModelProperty(value = "患者姓名", required = true)
    private String flowPatientName;

    @NotBlank
    @ApiModelProperty(value = "患者手机号", required = true)
    private String flowPatientMobile;

    @NotNull
    @ApiModelProperty(value = "金额", required = true)
    private Float flowPrice;

    @NotBlank
    @ApiModelProperty(value = "渠道", required = true)
    private String flowChannel;

    @ApiModelProperty("退款原因")
    private String flowRefundReason;

    @ApiModelProperty("对应订单")
    private String flowOrderNo;

    @ApiModelProperty("血糖仪")
    private String flowGlucometer;

    @ApiModelProperty(value = "创建月份", hidden = true)
    private String flowCreateMonth;

    @NotBlank
    @ApiModelProperty(value = "机构编码", required = true)
    private String orgCode;

    public PayRefundFlowDetail parseFromPo(DtrdEntRdPayRefundFlow po) {
        dataId = po.getDataId();
        flowDoctorId = po.getFlowDoctorId();
        flowType = po.getFlowType();
        flowPatientId = po.getFlowPatientId();
        flowPatientName = po.getFlowPatientName();
        flowPatientMobile = po.getFlowPatientMobile();
        if (po.getFlowPrice() != null) {
            flowPrice = StringUtil.StrTrimFloat(OrderUtil.changeF2Y((long)po.getFlowPrice()));
        }
        flowChannel = po.getFlowChannel();
        flowRefundReason = po.getFlowRefundReason();
        flowOrderNo = po.getFlowOrderNo();
        flowGlucometer = po.getFlowGlucometer();
        flowCreateMonth = po.getFlowCreateMonth();
        orgCode = po.getOrgCode();
        return this;
    }
}
